var app=new Vue({
    el: '#app',
    data:{
        help:{},
        isDisabled: false,
        ue: null,
        dicts:{
            type: []
        },
        helpRules: {
            hTitle: [
                { required: true,min: 2, max: 32, message: '文档标题长度在2-32个字符', trigger: 'blur' }
            ],
            hCode: [
                {  required: true, message: '请填写文档编码', trigger: 'blur' }
            ],
            hUrl: [
                {  message: '请填写文档地址', trigger: 'blur' }
            ],
            hType: [
                { required: true, message: '请至少选择一个文档类型', trigger: 'change' }
            ]
        }
    },
    mounted: function(){
        this.ue = UE.getEditor('editor');
    },
    destoryed: function() {
        this.ue.destory();
    },
    methods:{
        init: function(){
            var _this=this;
            setTimeout(function(){
                _this.initDict();
            },100);
        },
        closeDialog: function(){
            jsmile.dialog.close();
        },
        editHelp: function(){
            var _this=this;
            _this.isDisabled=true;
            this.$refs['help'].validate(function(valid) {
                if (valid) {
                    _this.help.helpContent=_this.ue.getContent();
                    jsmile.http.sendJson({
                        url:jsmile.url+"/sys/help/update",
                        data:_this.help
                    }).done(function(res){
                        jsmile.msg.success("修改文档信息成功!");
                        jsmile.dialog.close();
                        top.$('#home')[0].contentWindow.app.query();
                    }).fail(function(res){
                        jsmile.msg.error(res.resMsg?res.resMsg:"修改文档失败!");
                    });
                } else {
                    return false;
                }
            });
        },
        /**
         * 初始化数据字典
         */
        initDict: function(){
            var _this=this;
            jsmile.http.sendJson({
                url:jsmile.url+"/sys/dict/findDictByCode",
                data:{"dictCode":"DH01"}
            }).done(function(res){
                _this.dicts.type=res.resData;
            });
        }
    }
});
$(function(){
    init();
    function init(){
        app.init();
    }
});